package com.park.platform.dao.hibernate;

import com.park.common.constant.IDBConstant;
import com.park.common.poo.AreaInfo;
import com.park.platform.dao.IAreaDao;
import org.apache.commons.lang.StringUtils;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/15.
 */
public class AreaDao extends HibernateDaoSupport implements IAreaDao {

    @Override
    public List<String> getDefaultValueListByAreaId(String areaId) {
        List<String> defaultValueList = new ArrayList<String>();
        if (StringUtils.isNotBlank(areaId)) {
            defaultValueList.add(areaId);

            while (true) {
                AreaInfo area = super.getHibernateTemplate().get(AreaInfo.class, areaId);
                if (area != null) {
                    String areaInfoParentId = area.getAreaParentId();
                    if (StringUtils.isBlank(areaInfoParentId) || areaInfoParentId.equals(IDBConstant.ROOT_FLAG)) {
                        break;
                    }
                    defaultValueList.add(0, areaInfoParentId);
                    areaId = areaInfoParentId;
                } else {
                    break;
                }

            }
        }
        return defaultValueList;
    }
}
